package com.jianyun.jyzs.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


import com.jianyun.jyzs.R;
import com.jianyun.jyzs.bean.Sign;

import java.util.List;

/**
 * Created by liml on 17/5/16.
 */

public class SignAdapter extends BaseAdapter{
    private Context act;
    private List<Sign> list;


    public SignAdapter(Context act, List<Sign> list) {
        this.act = act;
        this.list = list;
    }

    public void setList(List<Sign> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list==null?0:list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        UserViewHolder mHolder = null;
        if(convertView == null) {
            convertView = View.inflate(act, R.layout.item_sign, null);
            mHolder = new UserViewHolder();
            mHolder.dateTime = (TextView) convertView.findViewById(R.id.dateTime);
            mHolder.location = (TextView) convertView.findViewById(R.id.location);
            convertView.setTag(mHolder);
        }else {
            mHolder = (UserViewHolder) convertView.getTag();
        }
        Sign po = list.get(position);
        mHolder.dateTime.setText(po.getDateTime());
        if(po.getAddress() != null && !po.getAddress().trim().equals("")){
            mHolder.location.setText(po.getAddress());
            mHolder.location.setTextColor(act.getResources().getColor(R.color.blue));
        }else{
            mHolder.location.setText(act.getString(R.string.sign_no_location));
            mHolder.location.setTextColor(act.getResources().getColor(R.color.content2));
        }
        return convertView;
    }
    class UserViewHolder {
        public TextView dateTime;
        public TextView location;
    }
}
